package com.zy.multiredis.config;
//package com.trace.zy.config;
//
//import java.time.Duration;
//import java.util.HashMap;
//import java.util.Map;
//
//import org.springframework.beans.factory.ObjectProvider;
//import org.springframework.boot.autoconfigure.data.redis.JedisClientConfigurationBuilderCustomizer;
//import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
//import org.springframework.boot.context.properties.bind.Bindable;
//import org.springframework.boot.context.properties.bind.Binder;
//import org.springframework.context.ApplicationContext;
//import org.springframework.context.ConfigurableApplicationContext;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.core.env.Environment;
//import org.springframework.data.redis.connection.RedisClusterConfiguration;
//import org.springframework.data.redis.connection.RedisSentinelConfiguration;
//import org.springframework.data.redis.connection.jedis.JedisClientConfiguration;
//import org.springframework.data.redis.connection.jedis.JedisClientConfiguration.JedisClientConfigurationBuilder;
//import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
//import org.springframework.data.redis.core.RedisTemplate;
//import org.springframework.util.StringUtils;
//
//import com.trace.zy.util.ManualRegistBeanUtil;
//
//import redis.clients.jedis.JedisPoolConfig;
//
//@Configuration
//public class RedisConfig extends AbstractRedisConnectionConfiguration {
//
//    private final ObjectProvider<JedisClientConfigurationBuilderCustomizer> builderCustomizers;
//
//    private Environment environment;
//
//    private ApplicationContext applicationContext;
//
//    protected RedisConfig(RedisProperties properties,
//        ObjectProvider<RedisSentinelConfiguration> sentinelConfigurationProvider,
//        ObjectProvider<RedisClusterConfiguration> clusterConfigurationProvider,
//        ObjectProvider<JedisClientConfigurationBuilderCustomizer> builderCustomizers, Environment environment,
//        ApplicationContext applicationContext) {
//        super(properties, sentinelConfigurationProvider, clusterConfigurationProvider);
//        this.environment = environment;
//        this.builderCustomizers = builderCustomizers;
//        this.applicationContext = applicationContext;
//        configJedis();
//    }
//
//    public void configJedis() {
//        Map<String, RedisProperties> map =
//            Binder.get(environment).bind("multi.redis", Bindable.mapOf(String.class, RedisProperties.class)).get();
//        for (Map.Entry<String, RedisProperties> entry : map.entrySet()) {
//            // 获取到每一个redis配置
//            RedisProperties redisProperties = entry.getValue();
//            // 创建redisfactory
//            JedisConnectionFactory jedisConnectionFactory = createJedisConnectionFactory(redisProperties);
//            // 创建tamplate,根据key作为spring中的类名
//            ManualRegistBeanUtil.registerBeanWithProperties((ConfigurableApplicationContext)applicationContext,
//                entry.getKey(), RedisTemplate.class, new HashMap<String, Object>() {
//                    {
//                        put("connectionFactory", jedisConnectionFactory);
//                    }
//                });
//        }
//    }
//   
//
//    // @Bean("${redisname1}")
//    // public Jedis configJedis() {
//    // Jedis jedis = new Jedis();
//    // Pool pool = new Pool();
//    // pool.setMaxActive(10);
//    // jedis.setPool(pool);;
//    // return jedis;
//    // }
//    //
//    // @Bean("${redisname2}")
//    // public Jedis configJedis2() {
//    // Jedis jedis = new Jedis();
//    // Pool pool = new Pool();
//    // pool.setMaxActive(20);
//    // jedis.setPool(pool);;
//    // return jedis;
//    // }
//
//}
